import { GameConfig } from "./GameConfig";

export default class GameLocalData{
    //读取user id
    public ReadUserID(){
        var userid = cc.sys.localStorage.getItem('userid');
        if(userid == null || userid == ""){
            return null;
        }
        return userid;
    }

    //清除user id
    public ClearUserID(){
        cc.sys.localStorage.removeItem('userid')
    }

    //保存user id
    public SaveUserID(userid) {
        cc.sys.localStorage.setItem('userid', userid);
    }

    public ReadClearDataFlag(){
        var flag = cc.sys.localStorage.getItem(GameConfig.ClearDataFlag);
        if(flag == null || flag == ""){
            return true;
        }
        return false;
    }

    //读取历史最高分
    public ReadHighestScore(){
        var highestScore = cc.sys.localStorage.getItem('highest_score');
        if(highestScore == null || highestScore == ""){
            return 0;
        }

        return highestScore;
    }

    public SetClearDataFlag(){
        cc.sys.localStorage.setItem(GameConfig.ClearDataFlag, 1);
    }

    //保存历史最高分
    public SaveHighestScore(highestScore){
        cc.sys.localStorage.setItem('highest_score', highestScore);
    }

    //读取视频剩余观察次数
    public ReadVideoCount(){
        return cc.sys.localStorage.getItem('video_count');
    }

    //保存视频剩余观察次数
    public SaveVideoCount(videoCount){
        cc.sys.localStorage.setItem('video_count', JSON.stringify(videoCount));
    }

    //移除存档
    public RemoveGameArchive(){
        cc.sys.localStorage.removeItem('archive')
    }

    //读档
    public ReadGameArchive(){
        var archiveData = cc.sys.localStorage.getItem('archive');
        if(archiveData){
            return archiveData;
        }
        return null;
    }

    //存档
    public SaveGameArchive(strArchiveData){
        if(strArchiveData){
            cc.sys.localStorage.setItem('archive', strArchiveData);
        }
    }

    public ReadLocalHighestScore(){
        var highestScore = cc.sys.localStorage.getItem('local_highest_score');
        if(highestScore == null || highestScore == ""){
            return 0;
        }

        return highestScore;
    }

    public SaveLocalHighestScore(highestScore){
        cc.sys.localStorage.setItem('local_highest_score', highestScore);
    }
}